package xfuzzy.alg_genetico.indeterminado.database;

import java.io.File;

import xfuzzy.xfghl.codification.DoubleChromosome;
import xfuzzy.xfghl.codification.Encoder;

public class DatabaseHandler {

	public synchronized static boolean saveConfigurations(DoubleChromosome cromosoma)  {
		
		ChromosomeDatabase chromosomedb = new ChromosomeDatabase();
		if (cromosoma.getCanonic().isEmpty())  {
			String canonic = Encoder.generarCanonico(cromosoma);
			cromosoma.setCanonic(canonic);
		}
		return chromosomedb.saveCodification(cromosoma.getCanonic(), cromosoma.getFitness());
	}
	
	public synchronized static double getFitness(DoubleChromosome chromosome)  {
		
		ChromosomeDatabase chromosomedb = new ChromosomeDatabase();
		return chromosomedb.getFitness(chromosome.getCanonic());
	}
	
	public synchronized static boolean deleteDatabase()  {
		
//		String os = System.getProperty("os.name").toLowerCase();
//		String command = "";
//		if (os.indexOf("win") >= 0)
//			
//		if (os.indexOf("linux") >= 0)
//			
//		if (os.indexOf("mac") >= 0)
		File file = new File("chromosome.db");
		if (file.exists())
			file.delete();
		return true;
	}
}
